
This guide will cover the setup and use of Vention’s MachineMotion™ Python Software Development Kit (SDK). After reading this guide, the user will be ready to deploy custom motion & control applications using Vention’s MachineMotion controller. It is recommended to read the MachineMotion Quick Start Guide to get familiar with the technology prior to reading this document.
Numerous systems are built by centralizing application level software on a host computer. The software role is to interact with various devices (i.e. robotic devices, sensors, proprietary products, data acquisition equipment) and deliver the required application behavior (see Exhibit 2).

Figure 1: Typical System Configuration
The use of MachineMotion and Python is perfectly suited for this type of application, especially where an easy to deploy motion control system is necessary.
Follow the steps below to set up the MachineMotion Python library:
Download the latest Python SDK 1.6.2
Extract the content on your computer. This location will be your workspace.
Install Python 2.7
Note for Windows Users: make sure to add Python.exe to the PATH environment carriable as shown in Figure 2.

Figure 2: Make sure to "Add python.exe to path" if intsalling on Windows.
Open the command promt (Window users) or the terminal (Mac or Linux Users) and run the following installations
pip install -U socketIO-clientpip install -U pathlibThe MachineMotion Python library is now ready to use. Programs can be created and ran from the workspace folder.
MachineMotion has two communication ports, one labeled USB and one labelled ETHERNET. Both use IP connectivity and have their own distinct IP address, see Figure 3.

Figure 3: MachineMotion Front Panel.
The IP address associated with the USB port is static (192.168.7.2 for Windows and 192.168.6.2 for Mac and Linux). It cannot be configured or modified. The USB port should be used for direct computer to MachineMotion connectivity.
The IP address associated with the ETHERNET port can be modified to suit the user’s network requirements. Refer to the How-to Guide: MachineMotion Network Setup for more details.
When creating a Python program to control the MachineMotion controller, the first step is always to create a MachineMotion instance. This will establish the communication with the actual controller and also expose different functions that can be used to send commands.
Following the creation of the MachineMotion instance, the network configuration and axis configuration need to be done. The functions to perform these steps are covered in this section.
Creates a MachineMotion instance and establishes the TCP/IP communication. This function is a constructor.
Handle in which incoming messages from the controller can be processed. The data will be passed as a string argument to the callback.
Ip address of the MachineMotion controller to connect to.
Instance created by the constructor.
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
print "Controller connected"Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller connectedConfigures the IP address of the controller Ethernet interface.
Ip allocation mode of the network, static or dhcp.
Desired static ip address to assign to the MachineMotion controller. Format is "nnn.nnn.nnn.nnnn", where n are numbers.
Network netmask. Format is "nnn.nnn.nnn.nnnn", where n are numbers.
Ip address of the network gateway. Format is "nnn.nnn.nnn.nnnn", where n are numbers.
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
machine_motion_example = machine_motion_example.configMachineMotionIp(NETWORK_MODE.static, "192.168.0.2", "255.255.255.0", "192.168.0.1")
print "--> Controller connected & ethernet interface configured (static)"Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
--> Controller connected & ethernet interface configured (static)from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
machine_motion_example = machine_motion_example.configMachineMotionIp(NETWORK_MODE.dhcp, "", "", "")
print "--> Controller connected & ethernet interface configured (dhcp)"Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
--> Controller connected & ethernet interface configured (dhcp)Configure the axis mechanical gain and micro-stepping settings to ensure that motion is accurate.
Axis to configure
u_step {MICRO_STEPS}
Micro-step setting
Mechanical gain of the axis in mm / turn
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Configure the axis number one, 8 uSteps and 150 mm / turn for a timing belt
machine_motion_example = machine_motion_example.configAxis(1, MICRO_STEPS.ustep_8, MECH_GAIN.timing_belt_150mm_turn)
print "--> Controller axis 1 configured"Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 M92 X10*99
Controller gCode responses ok
--> Controller axis 1 configuredSave a key-value pair on the controller.
Key to identify the data
Dictionary containing the data to save
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Saving a string on the controller
machine_motion_example = machine_motion_example.saveData("data_1", "save_this_string_on_the_controller")
print "--> Data sent on controller"Retrieve a key-value pair that was saved on the controller.
Key is a string that identifies the data to retrieve
Function to invoke once the data is available. The data will be passed as an argument to the callback as a serialized JSON string.
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
# Define a callback to print the data retrieved using the getData function
def printGetDataResult(data):
print "--> Retrieved data = " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Saving a string on the controller
machine_motion_example.saveData("data_1", "save_this_string_on_the_controller")
machine_motion_example.getData("data_1", printGetDataResult)Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
--> Retrieved data = {"data": "save_this_string_on_the_controller", "fileName": "data_1"}Blocking function that waits for the MachineMotion controller to ackowledge the command before continuing code execution. This is a code flow control function.
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Homing axis one
machine_motion_example.emitHome(1)
# Wait for the message to be acknowledged by the motion controller
while machine_motion_example.isReady() != "true": pass
print "--> This line executes after the motion controller has acknowledged the reception of the command."Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 G28 X*105
Controller gCode responses X:0.00 Y:0.00 Z:0.00 E:0.00 Count X: 0 Y:0 Z:0
Controller gCode responses ok
--> This line executes after the motion controller has acknowledged the reception of the command.Blocking function that holds the program execution until the last motion command sent completes. As long as the machine has not finised its last movement, code execution will be blocked.
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Homing axis one
machine_motion_example.emitHome(1)
# Wait for the message to be acknowledged by the motion controller
while machine_motion_example.isReady() != "true": pass
machine_motion_example.waitForMotionCompletion()
print "--> This line executes after the motion controller has acknowledged the reception of the command."Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 G28 X*105
Controller gCode responses X:0.00 Y:0.00 Z:0.00 E:0.00 Count X: 0 Y:0 Z:0
Controller gCode responses ok
Controller gCode responses echo:N3 V0*59
A motion status was requested
move is in progress
Controller gCode responses Motion Status = COMPLETED
Controller gCode responses ok
Controller gCode responses echo:N4 V0*60
A motion status was requested
Move was completed
Controller gCode responses Motion Status = COMPLETED
--> This line executes after the motion controller has acknowledged the reception of the command.
Controller gCode responses okImmediately stops motion on all axes.
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Send a stop command to the Machine (even if it is not moving yet !)
machine_motion_example.emitStop()
print "--> Machine Stopped"Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 M410*36
Controller gCode responses ok
--> Machine StoppedMoves all carriages to their home location sequentially, axis one to axis three.
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Homing all the axes of the controller sequentially
machine_motion_example.emitHomeAll()
machine_motion_example.waitForMotionCompletion()
print "--> All axes are now at home position."Moves the carriage of the corresponding axis to its home location.
Axis to move to home location
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Homing axis one
machine_motion_example.emitHome(1)
machine_motion_example.waitForMotionCompletion()
print "--> Axis 1 is now at home position."Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 G28 X*105
Controller gCode responses X:0.00 Y:0.00 Z:0.00 E:0.00 Count X: 0 Y:0 Z:0
Controller gCode responses ok
Controller gCode responses echo:N3 V0*59
A motion status was requested
move is in progress
Controller gCode responses Motion Status = COMPLETED
Controller gCode responses ok
Controller gCode responses echo:N4 V0*60
A motion status was requested
Move was completed
Controller gCode responses Motion Status = COMPLETED
--> Axis 1 is now at home position.
Controller gCode responses okConfigures the travel speed. Travel speed applies to combined axis moves and single axis moves.
Motion speed in millimeters per minute
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Configuring the travel speed to 10 000 mm / min
machine_motion_example.emitSpeed(10000)
print "--> Machine moves are not set to 10 000 mm / min"Configures the travel acceleration. Travel acceleration applies to combined axis moves and single axis moves.
Motion speed in millimeters per minute
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Configuring the travel speed to 1000 mm / second^2
machine_motion_example.emitAcceleration(1000)
print "--> Machine moves are not set to accelerate @ 1000 mm / second^2"Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 M204 T1000*82
Controller gCode responses Setting Travel Acceleration: 1000.00
Controller gCode responses ok
--> Machine moves are not set to accelerate @ 1000 mm / second^2Configures the travel acceleration. Travel acceleration applies to combined axis moves and single axis moves.
Axis to move to home location
Position of the carriage
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Configuring the travel speed to 10 000 mm / min
machine_motion_example.emitSpeed(10000)
# Configuring the travel speed to 1000 mm / second^2
machine_motion_example.emitAcceleration(1000)
# Homing axis one
machine_motion_example.emitHome(1)
machine_motion_example.waitForMotionCompletion()
# Move the axis one to position 100 mm
machine_motion_example.emitAbsoluteMove(1, 100)
machine_motion_example.waitForMotionCompletion()
print "--> Example completed."Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 G0 F10000*124
Controller gCode responses ok
Controller gCode responses echo:N3 M204 T1000*83
Controller gCode responses Setting Travel Acceleration: 1000.00
Controller gCode responses ok
Controller gCode responses echo:N4 G28 X*111
Controller gCode responses echo:busy: processing
Controller gCode responses X:0.00 Y:0.00 Z:0.00 E:0.00 Count X: 0 Y:0 Z:0
Controller gCode responses ok
Controller gCode responses echo:N5 G90*21
Controller gCode responses ok
Controller gCode responses echo:N6 G0 X100*102
Controller gCode responses ok
--> Example completed.Moves the gantry to a relative position based on the current gantry location.
Axis to move to home location
Motion direction
Distance to move in mm
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Configuring the travel speed to 10 000 mm / min
machine_motion_example.emitSpeed(10000)
# Configuring the travel speed to 1000 mm / second^2
machine_motion_example.emitAcceleration(1000)
# Homing axis one
machine_motion_example.emitHome(1)
# Move the axis one to position 100 mm
machine_motion_example.emitAbsoluteMove(1, 100)
machine_motion_example.waitForMotionCompletion()
# Move the axis one by a negative increment of 100 mm
machine_motion_example.emitRelativeMove(1, "negative", 100)
machine_motion_example.waitForMotionCompletion()
print "--> Example completed."Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 G0 F10000*124
Controller gCode responses ok
Controller gCode responses echo:N3 M204 T1000*83
Controller gCode responses Setting Travel Acceleration: 1000.00
Controller gCode responses ok
Controller gCode responses echo:N4 G28 X*111
Controller gCode responses X:0.00 Y:0.00 Z:0.00 E:0.00 Count X: 0 Y:0 Z:0
Controller gCode responses ok
Controller gCode responses echo:N5 G90*21
Controller gCode responses ok
Controller gCode responses echo:N6 G0 X100*102
Controller gCode responses ok
Controller gCode responses echo:N7 G91*22
Controller gCode responses ok
Controller gCode responses echo:N8 G0 X-100*69
--> Example completed.
Controller gCode responses okSends a direct G-Code string command. See the G-Code Commands section for more details.
G-Code command to send to the controller
none
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Configuring the travel speed to 10 000 mm / min
machine_motion_example.emitSpeed(10000)
# Configuring the travel speed to 1000 mm / second^2
machine_motion_example.emitAcceleration(1000)
# Homing axis one
machine_motion_example.emitHome(1)
machine_motion_example.waitForMotionCompletion()
# Use the G0 command to move both axis one and two by 500mm at a travel speed of 10 000 mm / minute
machine_motion_example.emitgCode("G0 X500 Y500 F10000")
machine_motion_example.waitForMotionCompletion()
print "--> Example completed."Controller gCode responses MachineMotion Session Start
Controller gCode responses echo:N0 M110 N0*125
Controller gCode responses ok
Controller gCode responses echo:N1 M111 S247*97
Controller gCode responses echo:DEBUG:ECHO,INFO,ERRORS,COMMUNICATION
Controller gCode responses ok
Controller gCode responses echo:N2 G0 F10000*124
Controller gCode responses ok
Controller gCode responses echo:N3 M204 T1000*83
Controller gCode responses Setting Travel Acceleration: 1000.00
Controller gCode responses ok
Controller gCode responses echo:N4 G28 X*111
Controller gCode responses echo:busy: processing
Controller gCode responses X:0.00 Y:3000.00 Z:0.00 E:0.00 Count X: 0 Y:24000 Z:0
Controller gCode responses ok
Controller gCode responses echo:N5 V0*61
Controller gCode responses Motion Status = COMPLETED
Controller gCode responses ok
Controller gCode responses echo:N6 V0*62
Controller gCode responses Motion Status = COMPLETED
Controller gCode responses ok
Controller gCode responses echo:N7 G0 X50 Y50 F10000*120
Controller gCode responses ok
Controller gCode responses echo:N8 V0*48
Controller gCode responses Motion Status = IN_PROGRESS
Controller gCode responses ok
Controller gCode responses echo:N9 V0*49
Controller gCode responses Motion Status = IN_PROGRESS
Controller gCode responses ok
Controller gCode responses echo:N10 V0*9
Controller gCode responses Motion Status = IN_PROGRESS
Controller gCode responses ok
Controller gCode responses echo:N11 V0*8
Controller gCode responses Motion Status = IN_PROGRESS
Controller gCode responses ok
Controller gCode responses echo:N12 V0*11
Controller gCode responses Motion Status = IN_PROGRESS
Controller gCode responses ok
Controller gCode responses echo:N13 V0*10
Controller gCode responses Motion Status = COMPLETED
--> Example completed.
Controller gCode responses okFunctions that exchange data with the MachineMotion controller (no movement involved).
Configures a control device on a specific MachineMotion port.
Port on which the device is connected
Type of device connected
Function to invoke once the data is available. The data will be passed as an argument to the callback as a serialized JSON string.
none
Status message containing
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
# Define a callback to invoked when a control device is attached to the controller
def attachControlDeviceCallback(data):
print "Attach control device callback: " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Attach (configure) a control device (an encoder in this case) to the MachineMotion controller.
machine_motion_controller.attachControlDevice("SENSOR4","ENCODER", attachControlDeviceCallback)deConfigures a control device on a specific MachineMotion port.
Port on which the device is connected
Function to invoke once the data is available. The data will be passed as an argument to the callback as a serialized JSON string.
none
Status message containing
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
# Define a callback to invoke when a control device is attached to the controller
def attachControlDeviceCallback(data):
print "Attach control device callback: " + data
# Define a callback to invoke when a control device is detached from the controller
def detachControlDeviceCallback(data):
print "Detach control device callback: " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Attach (configure) a control device (an encoder in this case) to the MachineMotion controller.
machine_motion_controller.attachControlDevice("SENSOR4","ENCODER", attachControlDeviceCallback)
# Some other code here ...
# Detach (deconfigure) a control device that was previously attached to the MachineMotion controller.
machine_motion_controller.detachControlDevice("SENSOR4", detachControlDeviceCallback)Read a given signal on a control device on a specific MachineMotion port.
Port on which the device is connected
Signal to read on the device
Function to invoke once the data is available. The data will be passed as an argument to the callback as a serialized JSON string.
none
{ port: "port", signal: "signal", value: "value read", error: "error message“}
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
# Define a callback to invoke when a control device is attached to the controller
def attachControlDeviceCallback(data):
print "Attach control device callback: " + data
# Define a callback to invoke when a control device is detached from the controller
def detachControlDeviceCallback(data):
print "Detach control device callback: " + data
# Define a callback to invoke when a control device is read
def readControlDeviceCallback(data):
print "Read control device callback: " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Attach (configure) a control device (an encoder in this case) to the MachineMotion controller.
machine_motion_controller.attachControlDevice("SENSOR4","ENCODER", attachControlDeviceCallback)
count = 0
for count in range (0, 100):
# Read the signal of a control device. SIGNAL0 of the encoder returns the relative position in turns. The encoder resets its position to 0 at power-on. Position is given in turns.
machine_motion_controller.readControlDevice("SENSOR4", "SIGNAL0", readControlDeviceCallback)
time.sleep(1)
# Detach (deconfigure) a control device that was previously attached to the MachineMotion controller.
machine_motion_controller.detachControlDevice("SENSOR4", detachControlDeviceCallback)DeConfigures a control device on a specific MachineMotion port.
Port on which the device is connected
Signal to read on the device
{ port: "port", signal: "signal", value: "value read", error: "error message“}
from MachineMotion import *
# Define a callback to process controller gCode responses (if desired)
def templateCallback(data):
print "Controller gCode responses " + data
# Define a callback to invoke when a control device is attached to the controller
def attachControlDeviceCallback(data):
print "Attach control device callback: " + data
# Define a callback to invoke when a control device is detached from the controller
def detachControlDeviceCallback(data):
print "Detach control device callback: " + data
# Define a callback to invoke when a control device is read
def readControlDeviceCallback(data):
print "Read control device callback: " + data
# Define a callback to invoke when a control device is written
def writeControlDeviceCallback(data):
print "Write control device callback: " + data
machine_motion_example = MachineMotion(templateCallback, DEFAULT_IP_ADDRESS.usb_windows)
# Attach (configure) a control device (an encoder in this case) to the MachineMotion controller.
machine_motion_controller.attachControlDevice("SENSOR4","IO_EXPANDER_GENERIC", attachControlDeviceCallback)
count = 0
for count in range (0, 100):
# Read the signal of a control device. SIGNAL0 of the IO expander. Returns True or Flase depending on the state of the IO.
machine_motion_controller.readControlDevice("SENSOR4", "SIGNAL0", readControlDeviceCallback)
time.sleep(1)
# Write the signal of a control device. SIGNAL0 of the IO expander.
machine_motion_controller.writeControlDevice("SENSOR4", "SIGNAL0", writeControlDeviceCallback)
time.sleep(1)
# Detach (deconfigure) a control device that was previously attached to the MachineMotion controller.
machine_motion_controller.detachControlDevice("SENSOR4", detachControlDeviceCallback)Open the command prompt (Windows users) or terminal (for Mac & Linux users).
Browse to the directory where you program is saved.
Execute your program.
python yourProgram.pyVarious status messages will be displayed on the console when the program starts running.
To stop the execution of the program, press CRTL + c
G-Code is a text based protocol broadly utilized to control the motion of multi axis machines. The API presented in the previous section employs it to communicate motion-related commands to the MachineMotion controller
More advanced users might wish to utilize specialized commands that are available via the G-Code protocol. The emitgCode (gCode) function presented in Table 6 can be used for this purpose.
The MachineMotion Python Library Package contains a list of G-Code commands available for advanced users. You can download it at the following link G-Code Reference Functions.
Some useful G-Code commands that can be utilized via the emitgCode function are listed below for convenience.
| G-Code Function ID | Description |
|---|---|
| M201 | Set Max Acceleration |
| M203 | Set Max Feedrate |
| M204 | Set Acceleration |
| G0 & G1 | Set Feedrate (Travel Speed) |
Table 1: G-Code Configuration Functions
| G-Code Function ID | Description |
|---|---|
| G90 | Set Absolute Motion |
| G91 | Set Relative Motion |
| G0 | Linear Move |
| G28 | Home |
Table 2: G-Code Control Functions
| G-Code Function ID | Description |
|---|---|
| M114 | Get Current Position |
| M119 | GEt EndStop States |
Table 3: G-Code Communication Functions
Note on Axis Mapping
Note that when using direct G-Code commands, the axis name mapping of Table 4 applies.
| G-Code Axis Name | MachineMotion Axis Name |
|---|---|
| X | 1 |
| Y | 2 |
| z | 3 |